<?php if (!defined('PmWiki')) exit();
/*  Copyright 2006-2007 Jon Haupt, based on BlogSimple by
    Hans Bracker.  This file is blogsimple2.php; you can redistribute
    it and/or modify it under the terms of the GNU General Public 
    License as published by the Free Software Foundation; either 
    version 2 of the License, or (at your option) any later version.  

    To use this script, simply place it into the cookbook/ folder
    and add the line
        include_once('cookbook/blogsimple/blogsimple2.php');
    to a local customization file.
    
    You also need to install commentboxplus.php.
*/
$RecipeInfo['BlogSimple2']['Version'] = '2007-02-16';

# settings you can change for time of day markup
SDV($BlogTimeEarlyMorning, "Clearly not sleeping in");
SDV($BlogTimeMorning, "Sometime after breakfast");
SDV($BlogTimeNoon, "Around lunch time");
SDV($BlogTimeAfternoon, "Afternoon");
SDV($BlogTimeEvening, "Sometime after dinner");
SDV($BlogTimeNight, "It was getting late");
SDV($BlogTimeAfterMidnight, "It was getting very late");
SDV($BlogTimeTooEarly, "Too early");

# add page variable {$Today}, formats today's date as yyyy-mm-dd
$FmtPV['$Today'] = 'strftime("%Y-%m-%d", time() )';
$FmtPV['$TodaySimple'] = 'strftime("%A %d %B", time() )';

# add page variable {$BlogDate} as page creation date, 12 September 2005
$FmtPV['$BlogDate'] = 'strftime("%d %B %Y", $page["ctime"])'; 
# add page variable {$BlogDate2} as page creation date for pagelisting purposes, 2005-09-12
$FmtPV['$BlogDate2'] = 'strftime("%Y-%m-%d", $page["ctime"])';
# add page variable {$BlogMonth2} as page creation date but only yyyy-mm, 2005-09
$FmtPV['$BlogMonth2'] = 'strftime("%Y-%m", $page["ctime"])';
# add another pv {$BlogMonth3} as page month spelled out e.g. September 2005
$FmtPV['$BlogMonth3'] = 'strftime("%B %Y", $page["ctime"])';

# time of day
SDV($BlogPostHours, array(
  '00' => $BlogTimeAfterMidnight,
  '01' => $BlogTimeAfterMidnight,
  '02' => $BlogTimeAfterMidnight,
  '03' => $BlogTimeTooEarly,
  '04' => $BlogTimeTooEarly,
  '05' => $BlogTimeTooEarly,
  '06' => $BlogTimeEarlyMorning,
  '07' => $BlogTimeEarlyMorning,
  '08' => $BlogTimeMorning,
  '09' => $BlogTimeMorning,
  '10' => $BlogTimeMorning,
  '11' => $BlogTimeNoon,
  '12' => $BlogTimeNoon,
  '13' => $BlogTimeNoon,
  '14' => $BlogTimeAfternoon,
  '15' => $BlogTimeAfternoon,
  '16' => $BlogTimeAfternoon,
  '17' => $BlogTimeAfternoon,
  '18' => $BlogTimeEvening,
  '19' => $BlogTimeEvening,
  '20' => $BlogTimeEvening,
  '21' => $BlogTimeEvening,
  '22' => $BlogTimeNight,
  '23' => $BlogTimeNight
  ));
$FmtPV['$BlogTimeOfDay'] = '$GLOBALS["BlogPostHours"][strftime("%H", $page["ctime"])]';

# add page variable {$LastModifiedByDate}
$FmtPV['$LastModifiedDate'] = 'strftime("%a %d %b", $page["time"])';

# patterns for list=blog
$SearchPatterns['blog'][] = '!\\.(All)?Recent(Changes|Uploads|Pages)$!';
$SearchPatterns['blog'][] = '!\.RecentChanges$!';
$SearchPatterns['blog'][] = '!\.GroupHeader$!';
$SearchPatterns['blog'][] = '!\.GroupFooter$!';
$SearchPatterns['blog'][] = '!\.GroupAttributes$!';
$SearchPatterns['blog'][] = '!\.SideBar$!';
$SearchPatterns['blog'][] = '!\.RightBar$!';
$SearchPatterns['blog'][] = '!\.PageTopMenu$!';
$SearchPatterns['blog'][] = '!\.PageFootMenu$!';
$SearchPatterns['blog'][] = '!\.HomePage$!';
$SearchPatterns['blog'][] = '!\.PageHeader$!';
$SearchPatterns['blog'][] = '!\.PageFooter$!';

# add (:if exists SomeGroup.SomeName:)
$Conditions['exists'] = "PageExists(\$condparm)";

# automatic loading of blog default pages
    $where = count($WikiLibDirs);
    if ($where>1) $where--;
    array_splice($WikiLibDirs, $where, 0, 
        array(new PageStore("$FarmD/cookbook/blogsimple2/wikilib.d/\$FullName")));

# change message for empty new comments page
$group = PageVar($pagename, '$Group');
if($group=='PostComments') {
  $DefaultPageTextFmt = 'Compose message, add author name, and click Post';
  }
# and for new archives page
if($group=='BlogArchive') {
  $DefaultPageTextFmt = '(:title {$BlogMonth}:)!!Archive for {$BlogMonth}
(:pagelist fmt=#blogarchive link=Category.Blog order=-ctime:)
----
Back to [[BlogArchive/Blog Archive]] -- or [[Main/Home Page]]';
  }

# also enable use of Site.SiteHeader and Site.SiteFooter
if ($group != $DefaultGroup && $group != $SiteGroup && $group != 'BlogArchive' && $group != 'PmWiki') {
  $GroupHeaderFmt = '(:include {$Group}.GroupHeader {$SiteGroup}.SiteHeader:)(:nl:)';
  $GroupFooterFmt = '(:nl:)(:include {$Group}.GroupFooter {$SiteGroup}.SiteFooter:)';
}

# create link back to main page for comments pages
$FmtPV['$BaseName'] = 'str_replace("-", ".", $name)';

# add Site.BlogListTemplates to the list of fmt=#xyz options for pagelists
$FPLTemplatePageFmt = array('{$Group}.PageListTemplates', '{$SiteGroup}.LocalTemplates', '{$SiteGroup}.PageListTemplates', '{$SiteGroup}.BlogListTemplates');
